home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#43 (Apr 89)
/
Designer CDEF Code
/
myCDEF.pas
< prev
Wrap
Pascal/Delphi Source File
|
1988-12-30
|
8KB
|
264 lines
UNIT myCDEF;
INTERFACE
FUNCTION DesignerButtonProc (varCode : integer;
theControl : ControlHandle;
message : integer;
param : longint) : longint;
IMPLEMENTATION
FUNCTION DesignerButtonProc; {}
{Custom controls for our controls}
CONST
inactive = 255;
indicator = 254;
regbutton = 3;
regcheck = 4;
rStop = 5;
rCaution = 6;
rGo = 7;
PROCEDURE DodrawCntl (theButton : integer;
ControlHdl : ControlHandle;
thePart : longint);
{draws our controls}
VAR
cRect, titleRect, designRect, tempRect, dimRect, onBox, offBox : Rect;
height, width, curve, start, titlewidth : integer;
titlestr, tempstr : str255;
PROCEDURE DeactiveButton (theRect : rect);
{dim the button}
BEGIN
PenPat(Gray);
PenMode(PatBic);
PaintRect(theRect);
PenNormal;
END;
BEGIN {of main drawing routines}
IF ControlHdl^^.contrlVis <> 0 THEN {visible?}
BEGIN
HLock(Handle(ControlHdl));
cRect := ControlHdl^^.contrlRect; {get the rectangle of control}
CASE ControlHdl^^.contrlRfCon OF {switch on button type}
regbutton : {regular button}
BEGIN
PenSize(2, 2);
curve := (cRect.bottom - cRect.top) DIV 2;
IF ControlHdl^^.contrlHilite > 0 THEN {hilight button?}
PenPat(black)
ELSE
PenPat(dkgray);
FrameRoundRect(cRect, curve, curve); {draw button}
PenNormal;
IF ControlHdl^^.contrlHilite = inactive THEN {inactive?}
BEGIN
tempRect := cRect;
InsetRect(tempRect, 2, 2);
DeactiveButton(tempRect);
END;
END;
regcheck : {checkbox}
BEGIN
EraseRect(cRect);
{could be better by just erasing what is needed}
titleRect := cRect;
titleRect.top := titleRect.bottom - 12;
designRect := cRect;
designRect.bottom := designRect.bottom - 12;
width := titleRect.right - titleRect.left;
height := designRect.bottom - designRect.top;
{draw control title}
TextFont(systemFont); {Set the font to draw in}
titlewidth := StringWidth(ControlHdl^^.contrlTitle);
titlestr := ControlHdl^^.contrlTitle;
TextBox(Pointer(ord(@titlestr) + 1), length(titlestr), titleRect, teJustLeft);
{draw ON/OFF, or LEFT/RIGHT, titles}
tempRect := designRect;
tempRect.left := tempRect.left + 20;
tempRect.bottom := tempRect.top + 12;
tempstr := 'LEFT';
TextBox(Pointer(ord(@tempstr) + 1), length(tempstr), tempRect, teJustRight);
tempRect.bottom := designRect.bottom;
tempRect.top := tempRect.bottom - 12;
tempstr := 'RIGHT';
TextBox(Pointer(ord(@tempstr) + 1), length(tempstr), tempRect, teJustRight);
TextFont(applFont); {Set the default application font}
{start drawing switch}
tempRect := designRect;
tempRect.right := tempRect.left + 40;
WITH tempRect DO {draw Switch}
BEGIN
width := right - left;
height := bottom - top;
onBox.top := top + (height DIV 2) - 10;
onBox.bottom := onBox.top + 20;
onBox.left := left + (width DIV 2) - 10;
onBox.right := onBox.left + 20;
IF ControlHdl^^.contrlHilite > 0 THEN {Hilite?}
PenSize(2, 2)
ELSE
PenSize(1, 1);
IF ControlHdl^^.contrlValue > 0 THEN
BEGIN {draw on}
FrameArc(onBox, 0, -270);
MoveTo(left + (width DIV 2), onBox.top);
Line(20, -20);
Line(10, 10);
LineTo(onBox.right, top + (height DIV 2));
END
ELSE
BEGIN {draw off}
FrameArc(onBox, 90, -270);
MoveTo(onBox.right, top + (height DIV 2));
Line(20, 20);
Line(-10, 10);
LineTo(left + (width DIV 2), onBox.bottom);
END;
END; { of with}
END;
rStop, rCaution, rGo : {radio button}
BEGIN
designRect := cRect;
titleRect := designRect;
titleRect.left := titleRect.left + 25;
titleRect.top := titleRect.top + 3;
designRect.right := designRect.left + 20;
{draw title of control}
TextFont(systemFont); {Set the font to draw in}
titlestr := ControlHdl^^.contrlTitle;
TextBox(Pointer(ord(@titlestr) + 1), length(titlestr), titleRect, teJustLeft);
TextFont(applFont); {Set the default application font}
height := designRect.bottom - designRect.top;
{switch on RefCon for radio button: stop, caution, and go}
{this is for radio button specific stuff}
CASE ControlHdl^^.contrlRfCon OF
rStop :
BEGIN
{draw box}
PenSize(2, 2);
MoveTo(designRect.left, designRect.bottom);
LineTo(designRect.left, designRect.top);
LineTo(designRect.right, designRect.top);
LineTo(designRect.right, designRect.bottom);
PenNormal;
PenPat(dkgray); {light color}
END;
rCaution :
BEGIN
{draw box}
PenSize(2, 2);
MoveTo(designRect.left, designRect.bottom);
LineTo(designRect.left, designRect.top);
MoveTo(designRect.right, designRect.top);
LineTo(designRect.right, designRect.bottom);
PenNormal;
PenPat(ltgray); {light color}
END;
rGo :
BEGIN
{draw box}
PenSize(2, 2);
MoveTo(designRect.left, designRect.top);
LineTo(designRect.left, designRect.bottom);
LineTo(designRect.right, designRect.bottom);
LineTo(designRect.right, designRect.top);
PenNormal;
PenPat(gray); {light color}
END;
OTHERWISE
;
END; { of case }
{draw light}
onBox := designRect;
InsetRect(onBox, 4, 4);
onBox.left := onBox.left + 1;
onBox.right := onBox.right + 1;
IF ControlHdl^^.contrlValue = 0 THEN {override pattern if off}
PenPat(white);
PaintOval(onBox);
PenNormal;
FrameOval(onBox);
IF ControlHdl^^.contrlHilite = inactive THEN {deactivate control}
BEGIN
tempRect := cRect;
DeactiveButton(tempRect);
END;
END;
END; {of button}
HUnLock(Handle(ControlHdl));
END; {of a visible control}
END;
FUNCTION DotestCntl (theButton : integer;
ControlHdl : ControlHandle;
thePoint : point) : longint;
{Test what part of control}
BEGIN
DotestCntl := 0; {initial value}
IF ControlHdl^^.contrlHilite <> inactive THEN {active control?}
BEGIN
IF ControlHdl^^.contrlHilite <> indicator THEN {indicator?}
BEGIN
IF PtInRect(thePoint, ControlHdl^^.contrlRect) THEN {in control's rect}
BEGIN
CASE ControlHdl^^.contrlRfCon OF {switch on control type}
{here is where you send a code back as to what type of control}
{and what part of that control was pressed. We only have controls}
{with one part, so no further testing is needed}
regbutton :
DotestCntl := inButton;
regcheck, rStop, rCaution, rGo :
DotestCntl := inCheckBox;
OTHERWISE
;
END;
END;
END
ELSE
DotestCntl := indicator;
END;
END;
PROCEDURE DocalcCRgns (theButton : integer;
ControlHdl : ControlHandle;
RegionHdl : RgnHandle);
{calculate region of control}
BEGIN
{easy as pie if rectangular}
RectRgn(RegionHdl, ControlHdl^^.contrlRect);
END;
BEGIN {main proc routine}
DesignerButtonProc := 0; {initialize the result}
{switch on what we are to do}
CASE message OF
drawCntl :
DodrawCntl(varCode, theControl, param); {draw}
testCntl :
DesignerButtonProc := DotestCntl(varCode, theControl, Point(param)); {test}
calcCRgns :
DocalcCRgns(varCode, theControl, RgnHandle(param)); {region}
OTHERWISE
;
END; {of case}
END;
END.